﻿Imports System.Drawing.Drawing2D
Public Class Winds
    ''' <summary>
    ''' 坐标线的画笔
    ''' </summary>
    Private m_PenProperty As New PenProperty '画笔的类
    Public Visible As Boolean = True  '等值线填充是否可见
    Private m_nSection As Integer = 16 '区域的个数
    Private m_PetalWidth As Double = 50
    Private m_ArraySpeedAndCorlors(4) As SpeedsAndColor
    Private m_ArraySpeed(m_nSection - 1, 4) As Double
    ''' <summary>
    ''' 颜色对象
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PenProperty() As PenProperty
        Get
            Return m_PenProperty
        End Get
        Set(ByVal value As PenProperty)
            m_PenProperty = value
        End Set
    End Property
    ''' <summary>
    ''' 区域的个数
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property nSection() As Integer
        Get
            Return m_nSection
        End Get
        Set(ByVal value As Integer)
            m_nSection = value
        End Set
    End Property
    ''' <summary>
    ''' 扇形的宽度的百分比
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PetalWidth() As Double
        Get
            Return m_PetalWidth
        End Get
        Set(ByVal value As Double)
            m_PetalWidth = value
        End Set
    End Property
    Property ArraySpeedAndCorlors() As SpeedsAndColor()
        Get
            Return m_ArraySpeedAndCorlors
        End Get
        Set(ByVal value As SpeedsAndColor())
            m_ArraySpeedAndCorlors = value
        End Set
    End Property
    ''' <summary>
    ''' 风向和对应的风段的频率
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property ArraySpeed() As Double(,)
        Get
            Return m_ArraySpeed
        End Get
        Set(ByVal value As Double(,))
            m_ArraySpeed = value
        End Set
    End Property
    Public Sub New()
        m_ArraySpeedAndCorlors(0) = New SpeedsAndColor
        m_ArraySpeedAndCorlors(0).Speed = 1.54
        m_ArraySpeedAndCorlors(0).Color = Color.Blue

        m_ArraySpeedAndCorlors(1) = New SpeedsAndColor
        m_ArraySpeedAndCorlors(1).Speed = 3.09
        m_ArraySpeedAndCorlors(1).Color = Color.SteelBlue

        m_ArraySpeedAndCorlors(2) = New SpeedsAndColor
        m_ArraySpeedAndCorlors(2).Speed = 5.14
        m_ArraySpeedAndCorlors(2).Color = Color.ForestGreen

        m_ArraySpeedAndCorlors(3) = New SpeedsAndColor
        m_ArraySpeedAndCorlors(3).Speed = 8.23
        m_ArraySpeedAndCorlors(3).Color = Color.Lime

        m_ArraySpeedAndCorlors(4) = New SpeedsAndColor
        m_ArraySpeedAndCorlors(4).Speed = 10.8
        m_ArraySpeedAndCorlors(4).Color = Color.Green

        m_ArraySpeed(0, 0) = 2.3
        m_ArraySpeed(0, 1) = 2.9
        m_ArraySpeed(0, 2) = 3.5
        m_ArraySpeed(0, 3) = 1.3
        m_ArraySpeed(0, 4) = 1.1

    End Sub

    Public Sub Draw(ByVal grap As Graphics, ByVal Calm As Double)
        'Dim TotalSpeed(Me.m_ArraySpeedAndCorlors.Length) As Double

        'For i As Integer = 0 To Me.m_nSection - 1
        '    For j As Integer = 0 To Me.m_ArraySpeedAndCorlors.Length - 1
        '        For k As Integer = 0 To j
        '            TotalSpeed(j) += Me.m_ArraySpeed(j, k)
        '        Next
        '    Next
        '    For j As Integer = 0 To Me.m_ArraySpeedAndCorlors.Length - 1
        '        FillWind(grap, Me.m_ArraySpeedAndCorlors(Me.m_ArraySpeedAndCorlors.Length - 1 - j).Color, Calm, TotalSpeed(Me.m_ArraySpeedAndCorlors.Length - 1 - j), i * (360 / Me.m_nSection), 360 / Me.m_nSection * m_PetalWidth * 0.01)
        '    Next
        'Next
        FillWind(grap, Color.Green, Calm, 5, 5, 10)

    End Sub
    ''' <summary>
    ''' 填充一个扇形区域
    ''' </summary>
    ''' <param name="grap"></param>
    ''' <param name="ForeColor"></param>
    ''' <param name="Calm"></param>
    ''' <param name="Speed"></param>
    ''' <param name="Angle"></param>
    ''' <param name="Arc"></param>
    ''' <remarks></remarks>
    Private Sub FillWind(ByVal grap As Graphics, ByVal ForeColor As Color, ByVal Calm As Double, ByVal Speed As Double, ByVal Angle As Double, ByVal Arc As Double) '求得某一条等值线
        If Visible Then
            '圆形区域
            Dim path As New GraphicsPath()
            Dim rect As New Rectangle(-(Calm + Speed), -(Calm + Speed), 2 * (Calm + Speed), 2 * (Calm + Speed))
            path.AddPie(rect, (Angle + Arc / 2), Arc)
            Dim region As New Region(path)
            Dim BackBrush As New SolidBrush(ForeColor)
            grap.FillRegion(BackBrush, region)


            m_PenProperty.Width = m_PenProperty.Width * PannelSetting.gScale / PannelSetting.PreScale '当比例发生变化时需要高速画笔的宽度
            Dim m_Pen As New Pen(Color.FromArgb(m_PenProperty.color))
            m_Pen.DashStyle = m_PenProperty.DashStyle
            m_Pen.Width = m_PenProperty.Width
            grap.DrawPath(m_Pen, path)
        End If

    End Sub
End Class
